| Conditions | 1 |
| Paths | 1 |
| Total Lines | 227 |
| Lines | 227 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | |||
| 4 | describe('40-bit from bytes', function() { |
||
| 5 | |||
| 6 | let byteData = require('../../index.js'); |
||
| 7 | |||
| 8 | // 40 bit unsigned |
||
| 9 | it('should turn 5 bytes (hex) to 1 unsigned 40-bit int (65535)', |
||
| 10 | function() { |
||
| 11 | assert.deepEqual(byteData.fromBytes( |
||
| 12 | ["ff","ff","0","0","0"], 40, {"base": 16, "signed": false}), |
||
| 13 | [65535]); |
||
| 14 | }); |
||
| 15 | it('should turn 5 bytes (hex) to 1 unsigned 40-bit int (32767)', |
||
| 16 | function() { |
||
| 17 | assert.deepEqual(byteData.fromBytes( |
||
| 18 | ["ff","7f","0","0","0"], 40, {"base": 16, "signed": false}), |
||
| 19 | [32767]); |
||
| 20 | }); |
||
| 21 | it('should turn 4 bytes (hex) to 0 unsigned 40-bit int (not enought bytes) (32767)', |
||
| 22 | function() { |
||
| 23 | assert.deepEqual(byteData.fromBytes( |
||
| 24 | ["ff","7f","0","0"], 40, {"base": 16, "signed": false}), |
||
| 25 | []); |
||
| 26 | }); |
||
| 27 | it('should turn 7 bytes (hex) to 1 unsigned 40-bit int (ignoring the extra bytes) (32767)', |
||
| 28 | function() { |
||
| 29 | assert.deepEqual(byteData.fromBytes( |
||
| 30 | ["ff","7f","0","0","0","ff","ff"], 40, {"base": 16, "signed": false}), |
||
| 31 | [32767]); |
||
| 32 | }); |
||
| 33 | |||
| 34 | it('should turn 5 bytes (hex) to 1 unsigned 40-bit int (549755813887)', |
||
| 35 | function() { |
||
| 36 | assert.deepEqual(byteData.fromBytes( |
||
| 37 | ["ff","ff","ff","ff","7f"], 40, {"base": 16, "signed": false}), |
||
| 38 | [549755813887]); |
||
| 39 | }); |
||
| 40 | it('should turn 5 bytes (bin) to 1 unsigned 40-bit int (500000000080)', |
||
| 41 | function() { |
||
| 42 | assert.deepEqual(byteData.fromBytes( |
||
| 43 | ["01010000", "10001000", "01010010", "01101010", "01110100" ], |
||
| 44 | 40, {"base": 2, "signed": false}), |
||
| 45 | [500000000080]); |
||
| 46 | }); |
||
| 47 | it('should turn 5 bytes (dec) to 1 unsigned 40-bit int (max range)', |
||
| 48 | function() { |
||
| 49 | assert.deepEqual(byteData.fromBytes( |
||
| 50 | ["ff","ff","ff","ff","ff"], 40, {"base": 16, "signed": false}), |
||
| 51 | [1099511627775]); |
||
| 52 | }); |
||
| 53 | it('should turn 5 bytes (bin) to 1 unsigned 40-bit int (max range)', |
||
| 54 | function() { |
||
| 55 | assert.deepEqual(byteData.fromBytes( |
||
| 56 | [255,255,255,255,255], 40, {"base": 10, "signed": false}), |
||
| 57 | [1099511627775]); |
||
| 58 | }); |
||
| 59 | |||
| 60 | |||
| 61 | it('should turn 5 bytes (hex) to 1 unsigned 40-bit int (149515627075)', |
||
| 62 | function() { |
||
| 63 | assert.deepEqual(byteData.fromBytes( |
||
| 64 | ["43","6a", "d3","cf","22"], 40, {"base": 16, "signed": false}), |
||
| 65 | [149515627075]); |
||
| 66 | }); |
||
| 67 | it('should turn 5 bytes (bin) to 1 unsigned 40-bit int (149515627075)', |
||
| 68 | function() { |
||
| 69 | assert.deepEqual(byteData.fromBytes( |
||
| 70 | ["01000011","01101010", "11010011","11001111","00100010"], |
||
| 71 | 40, {"base": 2, "signed": false}), |
||
| 72 | [149515627075]); |
||
| 73 | }); |
||
| 74 | it('should turn 5 bytes (bin) to 1 unsigned 40-bit int (149515627075) (padding)', |
||
| 75 | function() { |
||
| 76 | assert.deepEqual(byteData.fromBytes( |
||
| 77 | ["1000011","1101010", "11010011","11001111","100010"], |
||
| 78 | 40, {"base": 2, "signed": false}), |
||
| 79 | [149515627075]); |
||
| 80 | }); |
||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | |||
| 85 | // 40 bit signed |
||
| 86 | |||
| 87 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-32768)', |
||
| 88 | function() { |
||
| 89 | assert.deepEqual(byteData.fromBytes( |
||
| 90 | ["0","80","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 91 | [-32768]); |
||
| 92 | }); |
||
| 93 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-65535)', |
||
| 94 | function() { |
||
| 95 | assert.deepEqual(byteData.fromBytes( |
||
| 96 | ["1","0","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 97 | [-65535]); |
||
| 98 | }); |
||
| 99 | it('should turn 6 bytes (hex) to 1 signed 40-bit int (ignore the extra byte) (-65535)', |
||
| 100 | function() { |
||
| 101 | assert.deepEqual(byteData.fromBytes( |
||
| 102 | ["1","0","ff","ff","ff","fe"], 40, {"base": 16, "signed": true}), |
||
| 103 | [-65535]); |
||
| 104 | }); |
||
| 105 | it('should turn 9 bytes (hex) to 1 signed 40-bit int (ignore the extra bytes) (-65535)', |
||
| 106 | function() { |
||
| 107 | assert.deepEqual(byteData.fromBytes( |
||
| 108 | ["1","0","ff","ff","ff","ff","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 109 | [-65535]); |
||
| 110 | }); |
||
| 111 | |||
| 112 | |||
| 113 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-1)', |
||
| 114 | function() { |
||
| 115 | assert.deepEqual(byteData.fromBytes( |
||
| 116 | ["ff","ff","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 117 | [-1]); |
||
| 118 | }); |
||
| 119 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-2)', |
||
| 120 | function() { |
||
| 121 | assert.deepEqual(byteData.fromBytes( |
||
| 122 | ["fe","ff","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 123 | [-2]); |
||
| 124 | }); |
||
| 125 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-3)', |
||
| 126 | function() { |
||
| 127 | assert.deepEqual(byteData.fromBytes( |
||
| 128 | ["fd","ff","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 129 | [-3]); |
||
| 130 | }); |
||
| 131 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-10)', |
||
| 132 | function() { |
||
| 133 | assert.deepEqual(byteData.fromBytes( |
||
| 134 | ["f6","ff","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 135 | [-10]); |
||
| 136 | }); |
||
| 137 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-100)', |
||
| 138 | function() { |
||
| 139 | assert.deepEqual(byteData.fromBytes( |
||
| 140 | ["9c","ff","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 141 | [-100]); |
||
| 142 | }); |
||
| 143 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-1000)', |
||
| 144 | function() { |
||
| 145 | assert.deepEqual(byteData.fromBytes( |
||
| 146 | ["18","fc","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 147 | [-1000]); |
||
| 148 | }); |
||
| 149 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-10000)', |
||
| 150 | function() { |
||
| 151 | assert.deepEqual(byteData.fromBytes( |
||
| 152 | ["f0","d8","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 153 | [-10000]); |
||
| 154 | }); |
||
| 155 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-100000)', |
||
| 156 | function() { |
||
| 157 | assert.deepEqual(byteData.fromBytes( |
||
| 158 | ["60", "79","fe","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 159 | [-100000]); |
||
| 160 | }); |
||
| 161 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-1000000)', |
||
| 162 | function() { |
||
| 163 | assert.deepEqual(byteData.fromBytes( |
||
| 164 | ["c0", "bd","f0","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 165 | [-1000000]); |
||
| 166 | }); |
||
| 167 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-32768)', |
||
| 168 | function() { |
||
| 169 | assert.deepEqual(byteData.fromBytes( |
||
| 170 | ["0","80","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 171 | [-32768]); |
||
| 172 | }); |
||
| 173 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-32768)', |
||
| 174 | function() { |
||
| 175 | assert.deepEqual(byteData.fromBytes( |
||
| 176 | ["8","80","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 177 | [-32760]); |
||
| 178 | }); |
||
| 179 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-12345)', |
||
| 180 | function() { |
||
| 181 | assert.deepEqual(byteData.fromBytes( |
||
| 182 | ["c7","cf","ff","ff","ff"], 40, {"base": 16, "signed": true}), |
||
| 183 | [-12345]); |
||
| 184 | }); |
||
| 185 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (-12345)', |
||
| 186 | function() { |
||
| 187 | assert.deepEqual(byteData.fromBytes( |
||
| 188 | ["00","00","00","00","80"], 40, {"base": 16, "signed": true}), |
||
| 189 | [-549755813888]); |
||
| 190 | }); |
||
| 191 | it('should turn 5 bytes (bin) to 1 signed 40-bit int (65535)', |
||
| 192 | function() { |
||
| 193 | assert.deepEqual(byteData.fromBytes( |
||
| 194 | ["ff","ff","0","0","0"], 40, {"base": 16, "signed": true}), |
||
| 195 | [65535]); |
||
| 196 | }); |
||
| 197 | it('should turn 5 bytes (hex) to 1 unsigned 40-bit int (32767)', |
||
| 198 | function() { |
||
| 199 | assert.deepEqual(byteData.fromBytes( |
||
| 200 | ["ff","7f","0","0","0"], 40, {"base": 16, "signed": false}), |
||
| 201 | [32767]); |
||
| 202 | }); |
||
| 203 | |||
| 204 | /* |
||
| 205 | it('should turn 5 bytes (hex) to 1 signed 40-bit int (min range)', |
||
| 206 | function() { |
||
| 207 | assert.deepEqual(byteData.fromBytes( |
||
| 208 | ["ff","ff","ff","ff","7f"], 16), |
||
| 209 | [-549755813888]); |
||
| 210 | }); |
||
| 211 | it('should turn 5 bytes (bin) to 1 signed 40-bit int (-500000000080)', |
||
| 212 | function() { |
||
| 213 | assert.deepEqual(byteData.fromBytes( |
||
| 214 | ["01010000", "10001000", "01010010", "01101010", "01110100" ], 2), |
||
| 215 | [-500000000080]); |
||
| 216 | }); |
||
| 217 | it('should turn 5 bytes (dec) to 1 signed 40-bit int (max range)', |
||
| 218 | function() { |
||
| 219 | assert.deepEqual(byteData.fromBytes( |
||
| 220 | ["ff","ff","ff","ff","ff"], 16), |
||
| 221 | [549755813887]); |
||
| 222 | }); |
||
| 223 | it('should turn 5 bytes (bin) to 1 signed 40-bit int (32767)', |
||
| 224 | function() { |
||
| 225 | assert.deepEqual(byteData.fromBytes( |
||
| 226 | [255,255,255,255,255]), |
||
| 227 | [32767]); |
||
| 228 | }); |
||
| 229 | */ |
||
| 230 | }); |
||
| 231 |